package DBUnitTests;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import junit.framework.Assert;

import org.junit.Test;

import servlets.SearchServlet;
import dataBase.DBInitializer;
import dataBase.magaers.CodeDBMngr;

public class TestSearchUI {
	Map<String,String> cidTitle = new HashMap<String, String>();
	SearchServlet searchS = new SearchServlet();
	CodeDBMngr cdb = null;
	
	public TestSearchUI() {
		try {
			DBInitializer.getInstance().initDB();
			cdb = CodeDBMngr.getInstance();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
//	@Before
	public void setUp() throws Exception {
		cidTitle.put("1", "yoni");
		cidTitle.put("2", "elad");
		cidTitle.put("3", "noa");
		cidTitle.put("4", "aiya");
	}

//	@Test
	public void testSendResult() throws FileNotFoundException{
		File test = new File("test.html");
		PrintWriter pw = new PrintWriter(test);
//		searchS.sendResult(cidTitle, pw);
		pw.close();
	}

//	@Test
	public void testSendResultUserAndCategory() throws FileNotFoundException{
		//Map<String, String> result = cdb.searchByCategory("yoni", "asimon");
		//Assert.assertEquals("lazy", result.get("2"));
	}
	
	@Test
	public void testSearch(){
		Map<String, String> result = cdb.search("sort", "algo", "bla", 1);
		Assert.assertEquals("lazy", result.get("2"));
	}
	
//	@Test
	public void testSearchByTitle(){
		cdb.searchByTitle("sort", "eladkravi@gmail.com", true);
	}
}
